import scala.io.Source
import scala.xml.{Elem, XML}

object xml extends App {

//  def main(args: Array[String]) = {

    /*
      Node（NodeSeq）有 \ "tag" 投影操作，直接子元素中寻找节点，
                      \\ "tag" 所有子元素中寻找节点
                      \ "_" 所有直接子节点
                      \ "@attr" 属性


    */

/*
    // 不验证dtd
    val factory = javax.xml.parsers.SAXParserFactory.newInstance()
    factory.setValidating(false)
    factory.setFeature("http://xml.org/sax/features/validation", false)
    factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false)
    factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
    factory.setFeature("http://xml.org/sax/features/external-general-entities", false)
    factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false)

    val r = XML.withSAXParser(factory.newSAXParser()).loadFile("path/to/file")*/

//      .loadFile("")得到的是根标签元素
    /*
    <root>
        <query>
            <docid>xxx-CMN-xxx</docid>
            ...
    </root>
     */

    val q = XML.loadFile("in/kbp2011.xml") \ "query" filter (_ \ "docid" contains "_CMN_")
    //TODO 上面 filter +括号之后不能继续接\方法了，为什么？
    val words = q \ "name" map (_.text)
    println(words.mkString)
//  }

}